@model UpdaterManagement.Models.VersionRelease

<nav aria-label="breadcrumb" class="breadcrumb-ace">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/">首页</a></li>
        <li class="breadcrumb-item"><a href="/Version">版本管理</a></li>
        <li class="breadcrumb-item active">新增版本</li>
    </ol>
</nav>

<div class="page-header">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h1 class="page-title">
                <i class="bi bi-plus-circle text-primary me-2"></i>新增版本
            </h1>
            <p class="page-subtitle">为产品添加新的版本发布，支持文件上传和操作手册</p>
        </div>
        <a href="/Version" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left me-2"></i>返回列表
        </a>
    </div>
</div>

<div class="row">
    <div class="col-lg-8">
        <div class="card-ace">
            <div class="card-header">
                <i class="bi bi-form-check me-2"></i>版本信息
            </div>
            <div class="card-body">
                <partial name="_ErrorAlert" />
                
                <form method="post" enctype="multipart/form-data">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-box-seam text-primary me-1"></i>产品选择
                                </label>
                                <select class="form-select form-control-ace" asp-for="ProductId" id="productSelect" required>
                                    <option value="">请选择产品</option>
                                    @if (ViewBag.Products != null)
                                    {
                                        @foreach (var product in ViewBag.Products as List<UpdaterManagement.Models.Product>)
                                        {
                                            <option value="@product.Id" data-name="@product.Name">@product.Name</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-tag text-primary me-1"></i>产品名称
                                </label>
                                <input type="text" class="form-control form-control-ace" asp-for="ProductName" 
                                       readonly style="background-color: #f8f9fa;" />
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-building text-primary me-1"></i>所属企业
                                </label>
                                <select class="form-select form-control-ace" asp-for="EnterpriseId" required>
                                    <option value="">请选择企业</option>
                                    @if (ViewBag.Enterprises != null)
                                    {
                                        @foreach (var enterprise in ViewBag.Enterprises as List<UpdaterManagement.Models.Enterprise>)
                                        {
                                            <option value="@enterprise.Id">@enterprise.Name</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-code-square text-primary me-1"></i>版本号
                                </label>
                                <input type="text" class="form-control form-control-ace" asp-for="Version" 
                                       placeholder="如: 1.0.1" required />
                                <div class="form-text">建议使用语义化版本号，如：1.0.1</div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label-ace">
                            <i class="bi bi-chat-text text-primary me-1"></i>版本描述
                        </label>
                        <textarea class="form-control form-control-ace" asp-for="Description" rows="4" 
                                  placeholder="版本更新说明，如：修复了登录问题，新增了用户管理功能..."></textarea>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label-ace">
                            <i class="bi bi-link text-primary me-1"></i>版本地址
                        </label>
                        <input type="url" class="form-control form-control-ace" asp-for="VersionUrl" 
                               placeholder="如: https://example.com/download/v1.0.1" />
                        <div class="form-text">
                            <i class="bi bi-info-circle me-1"></i>可选，版本下载或访问地址
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-file-earmark-zip text-primary me-1"></i>版本文件
                                </label>
                                <input type="file" class="form-control form-control-ace" name="versionFile" 
                                       accept=".zip,.rar,.7z" />
                                <div class="form-text">
                                    <i class="bi bi-info-circle me-1"></i>支持zip、rar、7z格式，最大100MB
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label-ace">
                                    <i class="bi bi-file-text text-primary me-1"></i>操作手册
                                </label>
                                <input type="file" class="form-control form-control-ace" name="manualFile" 
                                       accept=".pdf,.doc,.docx" />
                                <div class="form-text">
                                    <i class="bi bi-info-circle me-1"></i>支持pdf、doc、docx格式
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input type="checkbox" class="form-check-input" asp-for="IsActive" checked />
                            <label class="form-check-label">
                                <i class="bi bi-toggle-on text-success me-1"></i>启用版本
                            </label>
                            <div class="form-text">启用后，该版本将对客户端可见</div>
                        </div>
                    </div>
                    
                    <div class="d-flex gap-2 pt-3 border-top">
                        <button type="submit" class="btn btn-ace-primary">
                            <i class="bi bi-check-circle me-2"></i>保存版本
                        </button>
                        <a href="/Version" class="btn btn-outline-secondary">
                            <i class="bi bi-x-circle me-2"></i>取消
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-lg-4">
        <div class="card-ace mb-3">
            <div class="card-header">
                <i class="bi bi-info-circle text-info me-2"></i>填写说明
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <h6 class="text-primary mb-2">版本号规范</h6>
                    <p class="small text-muted mb-2">建议使用语义化版本号：</p>
                    <ul class="small text-muted">
                        <li><strong>主版本号</strong>：不兼容的API修改</li>
                        <li><strong>次版本号</strong>：向下兼容的功能性新增</li>
                        <li><strong>修订号</strong>：向下兼容的问题修正</li>
                    </ul>
                </div>
                
                <div class="mb-3">
                    <h6 class="text-primary mb-2">文件要求</h6>
                    <div class="small text-muted">
                        <div class="mb-2">
                            <i class="bi bi-file-zip text-success me-1"></i>
                            <strong>版本文件：</strong>包含程序更新文件的压缩包
                        </div>
                        <div>
                            <i class="bi bi-file-text text-info me-1"></i>
                            <strong>操作手册：</strong>版本更新的详细说明文档
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card-ace">
            <div class="card-header">
                <i class="bi bi-lightbulb text-warning me-2"></i>温馨提示
            </div>
            <div class="card-body">
                <div class="alert alert-warning">
                    <i class="bi bi-exclamation-triangle me-2"></i>
                    <strong>注意：</strong>版本创建后不可修改版本号，请确认无误后再提交。
                </div>
                <div class="alert alert-info">
                    <i class="bi bi-info-circle me-2"></i>
                    <strong>建议：</strong>上传文件前请确保文件完整性，避免客户端更新失败。
                </div>
            </div>
        </div>
    </div>
</div>

<script>
// 产品选择变化时自动填充产品名称
document.getElementById('productSelect').addEventListener('change', function() {
    const selectedOption = this.options[this.selectedIndex];
    if (selectedOption.value) {
        const productName = selectedOption.dataset.name;
        document.querySelector('input[name="ProductName"]').value = productName;
    } else {
        document.querySelector('input[name="ProductName"]').value = '';
    }
});

// 文件上传预览
document.querySelectorAll('input[type="file"]').forEach(input => {
    input.addEventListener('change', function() {
        const file = this.files[0];
        if (file) {
            const fileSize = (file.size / 1024 / 1024).toFixed(2);
            const helpText = this.nextElementSibling;
            helpText.innerHTML = `<i class="bi bi-check-circle text-success me-1"></i>已选择: ${file.name} (${fileSize}MB)`;
        }
    });
});
</script>